package com.huangsiyuan.myepidemic.common;

import org.apache.log4j.Logger;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class DateConverter implements Converter<String,Date> {
    public static Logger logger= Logger.getLogger(DateConverter.class);

    private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    @Override
    public Date convert(String s) {
        if(s==null||s.length()==0){
            return null;
        }
        Date date=null;
        try {
            date=sdf.parse(s);
        } catch (ParseException e) {
            logger.error("轉換提交的參數"+s+"為日期值時出錯："+e.getMessage());
        }
        return date;
    }
}
